      1  import java.io.File;

      2  import java.io.IOException;

      3  import java.util.ArrayList;

      4  import java.util.Scanner;

      5

      6  /**

      7     A bank contains customers.

      8  */

      9  public class Bank

     10  {

     11     private ArrayList<Customer> customers;

     12

     13     /**

     14        Constructs a bank with no customers.

     15     */

     16     public Bank()

     17     {

     18        customers = new ArrayList<Customer>();

     19     }

     20

     21     /**

     22        Reads the customer numbers and pins.

     23        @param filename the name of the customer file

     24     */

     25     public void readCustomers(String filename)

     26           throws IOException

     27     {

     28        Scanner in = new Scanner(new File(filename));

     29        while (in.hasNext())

     30        {

     31           int number = in.nextInt();

     32           int pin = in.nextInt();

     33           Customer c = new Customer(number, pin);

     34           addCustomer(c);

     35        }

     36        in.close();

     37     }

     38

     39     /**

     40        Adds a customer to the bank.

     41        @param c the customer to add

     42     */

     43     public void addCustomer(Customer c)

     44     {

     45        customers.add(c);

     46     }

     47

     48     /**

     49        Finds a customer in the bank.

     50        @param aNumber a customer number

     51        @param aPin a personal identification number

     52        @return the matching customer, or null if no customer

     53        matches

     54     */

     55     public Customer findCustomer(int aNumber, int aPin)

     56     {

     57        for (Customer c : customers)

     58        {

     59           if (c.match(aNumber, aPin))

     60           {

     61              return c;

     62           }

     63        }

     64        return null;

     65     }

     66  }

     67

     68